package com.book.lizhi.adapter;

import java.util.List;

import android.app.Application;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.book.lizhi.AppApplication;
import com.book.lizhi.R;
import com.book.lizhi.model.GasStationModel;
import com.book.lizhi.widget.RatioImageView;

public class GasStationAdapter extends AppAdapter {

	public GasStationAdapter(Context context, List<?> list) {
		super(context, list);
	}

	@Override
	public View getView(int position, View convertView, Context context) {
		ViewHolder holder;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.gas_station_item_layout, null);
			holder=ViewHolder.create(convertView);
			convertView.setTag(holder);
		}else {
			holder=(ViewHolder) convertView.getTag();
		}
		
		GasStationModel model=(GasStationModel) getItem(position);
		holder.gasImageview.setDefaultImageResId(R.drawable.image_default);
		holder.gasImageview.setErrorImageResId(R.drawable.image_default);
		holder.gasImageview.setHeightRatio(model.height/model.width);
		holder.gasImageview.setImageUrl(model.img, AppApplication.instance.imageLoader);
		holder.gasTextview.setText(model.brief);
		return convertView;
	}
	
	private static class ViewHolder {
		public final RatioImageView gasImageview;
		public final TextView gasTextview;

		private ViewHolder(RatioImageView gasImageview, TextView gasTextview) {
			this.gasImageview = gasImageview;
			this.gasTextview = gasTextview;
		}

		public static ViewHolder create(View convertView) {
			RatioImageView gasImageview = (RatioImageView)convertView.findViewById( R.id.gas_imageview );
			TextView gasTextview = (TextView)convertView.findViewById( R.id.gas_textview );
			return new ViewHolder( gasImageview, gasTextview );
		}
	}

}
